﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;
using System.Data.SqlClient;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 信息文档合发单位 数据类
    /// </summary>
    public class DocumentUnionPubEmpl
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public DocumentUnionPubEmpl()
        {
        }

        /// <summary>
        /// 获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-08-16</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="docId">文档编号</param>
        /// <returns>DataSet对象</returns>
        public DataSet GetModelList(string entityNo, decimal docId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEntityNo,FDeptNo,FEmplNo,FDocId,FEmpName ");
            strSql.Append(" FROM v_documentUnionPubEmpl ");
            strSql.Append(" where FEntityNo=@FEntityNo and FDocId=@FDocId ");

            SqlParameter[] parameters = {
					new SqlParameter("@FDocId", SqlDbType.Decimal),
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = docId;
            parameters[1].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-08-16</date>
        /// </summary>
        /// <param name="row">DataRow对象</param>
        /// <returns>信息合发实体对象</returns>
        public ElingOA6_Admin_DSJCJ.Model.DocumentUnionPubEmpl DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.DocumentUnionPubEmpl model = new ElingOA6_Admin_DSJCJ.Model.DocumentUnionPubEmpl();
            if (row != null)
            {
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FEmplNo"] != null)
                {
                    model.FEmplNo = row["FEmplNo"].ToString();
                }
                if (row["FDocId"] != null && row["FDocId"].ToString() != "")
                {
                    model.FDocId = decimal.Parse(row["FDocId"].ToString());
                }
                if (row.Table.Columns.Contains("FEmpName"))
                {
                    model.FEmpName = row["FEmpName"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 合发数据根据FDocId,FDeptNo分组，用于查询某文档的所有部门编号
        /// <creator>sunlj</creator>
        /// <date>2013-10-16</date>
        /// </summary>
        public DataSet GetList_DocIdAndDeptNo(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FDocId,FDeptNo ");
            strSql.Append(" FROM t_documentUnionPubEmpl group by FDocId,FDeptNo");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.DocumentUnionPubEmpl DataRowToModel2(DataRow row)
        {
            Model.DocumentUnionPubEmpl model = new Model.DocumentUnionPubEmpl();
            if (row != null)
            {
                if (row["FDocId"] != null && row["FDocId"].ToString() != "")
                {
                    model.FDocId = decimal.Parse(row["FDocId"].ToString());
                }
                //if (row["FEntityNo"] != null)
                //{
                //    model.FEntityNo = row["FEntityNo"].ToString();
                //}
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                //if (row["FEmplNo"] != null)
                //{
                //    model.FEmplNo = row["FEmplNo"].ToString();
                //}
            }
            return model;
        }



    }
}
